'use strict';
var HOST = 'https://szchaxun.jucheng01.net/';
//  var HOST = 'http://www.szchaxun.com/';
//get请求方法
function fetchGet(url, data, callback) {
 wx.request({
    method: 'GET',
    url: url,
    data: data,
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    success: function (res) {
      callback(null, res.data)
    },
    fail: function (e) {
      callback(e)
    }
  })
}

// post请求方法
function fetchPost(url, data, callback) {
  wx.request({
    method: 'POST',
    url: url,
    data: data,
    header: { 'content-type': 'application/x-www-form-urlencoded' },
    success: function (res) {
      callback(null, res.data)
    },
    fail: function (e) {
      callback(e)
    }
  })
}

function getUserInfo(cb) {
  var that = this;
  wx.getUserInfo({
    lang: 'zh_CN',
    success: function (res) {
      typeof cb == "function" && cb(res.userInfo)
    }
  })
}

function alert(msg,callback) {
	wx.showModal({
		content: msg,
		showCancel:false,
		success: function(res) {
			if(res.confirm){
				if(callback){
					callback(res.data)
				}
			}else if(res.cancel) {
				console.log('用户点击取消')
			}
		}
	});
}


function call(linktel){
	wx.makePhoneCall({
		phoneNumber: linktel
	})
}

function openlocation(lat,lng){
	wx.openLocation({
		latitude: lat,
		longitude: lng,
		scale: 28
    })
}

function title(title){
	wx.setNavigationBarTitle({
		title: title
	});
}

module.exports = {
    HOST:HOST,
    fetchGet: fetchGet,	//get方法
    fetchPost: fetchPost,	//post方法
	getUserInfo: getUserInfo,//获取用户信息
    alert:alert,		//alert方法
    call:call,		//一键拨号
    openlocation:openlocation,	//导航
    title:title		//设置页面标题
}
